<?php

//session_start();
$sessionID = $_COOKIE['PHPSESSID'];

if(isset($_POST['action']) != '' || isset($_GET['action']) != '') {
	if($_POST['action'] == '')
	{
		$action 	= $_GET['action'];
		$productID	= $_GET['productID'];
		$noJavaScript = 1;
	} else {
		$action 	= $_POST['action'];
		$productID	= $_POST['productID']; 
		$noJavaScript = 0;
	}
}

if (isset($action) == "deleteFromBasket"){
	$conn = oci_connect("Klimo", "123", "localhost/XE");
	$query = "DELETE FROM koszyk WHERE ID_FILMU = " . $productID . " AND KOSZYK_SESJA = '" . $sessionID . "'";
	$q = oci_parse($conn,$query);
	oci_execute($q) or die('Error, delete query failed');
		
	if ($noJavaScript == 1) {
		header("Location: ../movies.php");
	}
	oci_close($conn);
	die();

}

function getBasket(){
	$conn = oci_connect("Klimo", "123", "localhost/XE");
	//session_start();
	$sessionID = $_COOKIE['PHPSESSID'];
	//echo $sessionID;
	$query  = "SELECT * FROM koszyk WHERE KOSZYK_SESJA = '" . $sessionID . "' ";
	$q = oci_parse($conn,$query);
	$result = oci_execute($q);
	$basketText = '';
	while($row = oci_fetch_array($q, OCI_ASSOC))
	{		
		$query2  = "SELECT * FROM film WHERE ID = " . $row['ID_FILMU'];
		$q2 = oci_parse($conn,$query2);
		$result2 = oci_execute($q2);
		$row2 = oci_fetch_array( $q2, OCI_ASSOC );
	
		$productID	 	= $row2['ID'];
		$productPoster 		= $row2['OKLADKA'];	
		$productName		= $row2['TYTUL_POL'];	
	
		$basketText = $basketText . '<li id="productID_' . $productID . '"><h6><a href=inc/deletefrombasket.php?action=deleteFromBasket&productID=' . $productID .
		' onClick="return false;"><img src="images/delete.png" id="deleteProductID_' . $productID . '"></a> ' . $productName . '</h6></li>';
		
	}
	echo $basketText;
}
	
?>